<template>
  <component :is="ModelDashBoard" />
</template>

<script>
const loadDashBoard = m => import(`@/components/rmcompents/dashboard_sub/${m}.vue`);
export default {
  name: "dashboard",
  data() {
    return {
      ModelDashBoard: null,
      CurModel: "",
      mode: 0,// 0 通用首页|1 快捷菜单首页|2 面板首页
    };
  },
  created() {
    // this.ModelDashBoard = () => import("@/components/rmcompents/dashboard_sub/default.vue");
    this.gethomeparam().then(() => {
      console.log('this.mode =', this.mode);
      if (this.mode == 2) {
        this.$bus.$on("changeModel", (model) => {
          //this.$router.push("/dashboard");//回到首页，先屏蔽，等首页全部完成，可以方便通过首页进入各菜单之后再开启
          this.RToModel(model);
        });
      }
      else if (this.mode == 1) {
        //快捷菜单类型的首页 - 比如美年
        this.ModelDashBoard = () => import("@/components/rmcompents/dashboard_sub/default_menu.vue");
      }
      else {
        //快捷菜单类型的首页 - 比如美年
        this.ModelDashBoard = () => import("@/components/rmcompents/dashboard_sub/default.vue");
      }
    });
  },
  methods: {
    ToDefault() {
      if (this.CurModel != "default") {
        this.CurModel = "default";
        this.ModelDashBoard = () => import("@/components/rmcompents/dashboard_sub/default.vue");
      }
    },
    RToModel(model) {
      if (this.CurModel != model) {
        import(`@/components/rmcompents/dashboard_sub/${model}.vue`).then(component => {
          if (component) {
            this.CurModel = model;
            this.ModelDashBoard = component.default;
          }
          else {
            this.ToDefault();
          }
        }).catch(() => {
          //再找一下这个模块是否有首页
          if (model.length > 3) {
            this.RToModel(model.substr(0, 3));
          } else {
            this.ToDefault();
          }
        });
      }
    },
    gethomeparam() {
      return new Promise((s, f) => {
        this.$tool
          .request({
            url: "/ucent/dashboard",
            method: "post",
            data: {
              action: "gethomeparam",
            },
          })
          .then((res) => {
            if (res.flag == "1") {
              this.mode = res.mode;
            }
            s();
          })
          .catch((e) => {
            s();
          });
      });
    },
  },
}
</script>
